package cn.trigram.config;

import com.alibaba.cloud.sentinel.feign.DefaultFallbackSentinelFeign;
import com.alibaba.csp.sentinel.SphU;
import feign.Feign;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;

@Configuration(proxyBeanMethods = false)
public class FeignConfiguration {

  @Primary
  @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
  @Bean
  @ConditionalOnClass({SphU.class, Feign.class})
  @ConditionalOnProperty("feign.sentinel.enabled")
  public Feign.Builder builder() {

    return DefaultFallbackSentinelFeign.builder();
  }

}
